package top.zhangjianyong.tools.utils;

import top.zhangjianyong.tools.entity.marirui.JJGZ;

import java.util.List;
import java.util.concurrent.*;

/**
 * @author ： zhangjianyong
 * @date ： 2022/10/17 9:35 AM
 */
public class MairuiUtil {

    private static ThreadPoolExecutor executor;

    private synchronized static ThreadPoolExecutor getPool() {
        if (executor != null) {
            return executor;
        }
        executor = new ThreadPoolExecutor(
                4,  // 核心线程数
                8,  // 最大线程数
                1,  // 空闲线程存活时间
                TimeUnit.MINUTES,  // 时间单位
                new LinkedBlockingQueue<>(500)  // 任务队列
        );
        return executor;
    }

    public static <T> Future<T> submit(Callable<T> callable) {
        return getPool().submit(callable);
    }


    public static String getMessage(List<JJGZ> jjgzs) {
        StringBuilder sb = new StringBuilder();
        for (JJGZ jjgz : jjgzs) {
            sb.append("------------------------\n");
            sb.append("代码： ").append(jjgz.getDm())
                    .append(" ").append("名称： ").append(jjgz.getMc())
                    .append("\n");
            sb.append("估值:").append(jjgz.getGz()).append("\n");
            sb.append("持仓比:").append(jjgz.getCcb()).append("\n");
            sb.append("持仓:").append(jjgz.getCc()).append("\n");
            sb.append("折现率:").append(jjgz.getZxl()).append("\n");
            sb.append("\n");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String dm = "09618.116";
        if (dm.contains(".")) {
            dm = dm.split("\\.")[0];
        }
        System.out.println(dm);
    }
}
